<?php
if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );
class website_statistics_manage extends CI_Controller {
	public function __construct() {
		session_start ();
		parent::__construct ();
		$this->load->helper ( "common" );
	}
	public function index() {
		$this->statistics_info ();
	}
	public function statistics_info() {
		$this->load->library ( "common/login_manage" );
		$this->login_manage->redirect_url_check_login ();
	
		$this->load->library ( "common/user_menu" );
		$data ['user_menu'] = $this->user_menu->get_user_menu ();
	
		$this->load->library ( "common/right_manage" );
		$data ['edit_statistics'] = false;
		if (! $this->right_manage->check_right ( "edit_statistics" )) {
			$data ['title'] = "权限不足";
			$data ['message'] = "你没有权限使用这个功能。";
			$this->load->view ( "common/error_tip", $data );
			return;
		}
		$this->load->library ( "website/statistics" );
		$data ['statistics_info'] = $this->statistics->query_statistics_info ( 1 );
		$this->load->view ( "website/statistics/statistics_info", $data );
	}
	
	public function edit_website_statistics() {
		$this->load->library ( "common/login_manage" );
		$this->login_manage->redirect_url_check_login ();
		
		$this->load->library ( "common/user_menu" );
		$data ['user_menu'] = $this->user_menu->get_user_menu ();
		
		$this->load->library ( "common/right_manage" );
		$data ['edit_statistics'] = false;
		if (! $this->right_manage->check_right ( "edit_statistics" )) {
			$data ['title'] = "权限不足";
			$data ['message'] = "你没有权限使用这个功能。";
			$this->load->view ( "common/error_tip", $data );
			return;
		}
		$this->load->library ( "website/statistics" );
		$data ['statistics_info'] = $this->statistics->query_statistics_info ( 1 );
		$this->load->view ( "website/statistics/edit_website_statistics", $data );
	}
	public function update_statistics() {
		$this->load->library ( "common/login_manage" );
		if ($this->login_manage->check_login () == false) {
			$data ['result'] = false;
			$data ['message'] = '请您先登录';
			echo json_encode ( $data );
			die ();
		}
		$this->load->library ( "common/right_manage" );
		if (! $this->right_manage->check_right ( "edit_statistics", $_SESSION ['user_id'] )) {
			$result ['result'] = false;
			$result ['message'] = '你没有权限使用这个功能';
			echo json_encode ( $result );
			die ();
		}
		$featured_id = $this->input->get_post ( "featured_id" );
		$statistics ['media_num'] = trim ( $this->input->get_post ( "media_num" ) );
		$statistics ['monitor_num'] = trim ( $this->input->get_post ( "monitor_num" ) );
		$statistics ['brand_num'] = $this->input->get_post ( "brand_num" );
		$statistics ['vendor_num'] = $this->input->get_post ( "vendor_num" );
		$statistics ['city_num'] = $this->input->get_post ( "city_num" );
		$statistics ['increase_proportion'] = $this->input->get_post ( "increase_proportion" );
		$this->load->library ( "website/statistics" );
		$this->load->helper ( "common" );
		$result = $this->statistics->update_statistics ( $statistics, 1 );
		echo JSON ( $result );
	}
}